Mega Code Archive
Dictionary
1) (Key) Membership (in, not in)
2) Add new key and value
3) Adding a Value to a Dictionary
4) Change value for existing key
5) Clear method removes all items from the dictionary
6) Compare dictionaries
7) Compare Dictionary Sizes
8) Compare with cmp()
9) Constructing a Dictionary
10) Copy method returns a duplicate shallow dictionary
11) Create dictionary from fromkeys() function
12) Create new dictionary from subset of keys
13) Create subset of keys
14) Creating, accessing and modifying a dictionary
15) Deleting Items from a Dictionary
16) Dict can be used with keyword arguments
17) Dictionaries may be created using the factory function dict()
18) Dictionary Keys Are Case-Sensitive
19) Dictionary methods
20) Dictionary Syntax
21) Fromkeys method creates a new dictionary with the given keys, each with a default corresponding value of None
22) Get list of keys
23) Get method is a way of accessing dictionary items
24) Get value by key
25) Get value from dictionary with default value
26) Access Values in Dictionaries
27) Remove Dictionary Elements and Dictionaries
28) Update Dictionaries
29) If you dont want to use None as the default value, you can supply your own default
30) Indexing a Dictionary
31) Items method returns all the items as a list of items in the form of (key, value)
32) Iterating Through a Dictionary
33) Iteritems method returns an iterator instead of a list
34) Keys() returns a list of the dictionarys keys
35) Len() returns the total number of items, that is, key-value pairs
36) Many to many dictionary
37) Mapping Type Related Functions with dict()
38) Mixing Data types in a Dictionary
39) Mixing the use of numbers and strings as keys
40) Modifying a Dictionary
41) Name and name would represent two completely distinct keys in the dictionary
42) One to many dictionary
43) Pop method returns the value corresponding to a given key, and then remove the key-value pair from the dictionary
44) Popitem pops off a random item
45) Retrieve value from key
46) Retrieving dictionary key list
47) Retrieving dictionary value list
48) Setdefault sets the value corresponding to the given key if it is not already in the dictionary
49) Setdefault()
50) Simple one to one dictionary
51) Sorted dictionary
52) String Formatting with Dictionaries
53) Swap keys for values
54) The Boolean has_key() and the in and not in operators are Boolean, returning True if a dictionary has that key and False otherw
55) The has_key method checks whether a dictionary has a given key
56) The keys, values, and items Functions
57) The update method updates one dictionary with the items of another
58) The values method returns a list of the values in the dictionary
59) To access individual dictionary elements, you use the familiar square brackets along with the key to obtain its value
60) To loop over the keys of a dictionary, you can use a plain for statement
61) Update() can be used to add the contents of one directory to another
62) Use the dict function to construct dictionaries from (key, value) pairs
63) Using Iterators with Sequences
64) Using the dictionary name will cause an iterator over that dictionary
65) You may supply your own default value